var path;
$(function(){
	var loginUser = $("#loginUser").val();
	
	if(loginUser=="001"){
		 $('#myaccrdion').accordion({animate:false,border:false,height:700,selected:0});
	}else{
		$('#myaccrdion').accordion({animate:false,border:false,selected:0});
	}
  path = getContextPath();
  $("#logtime").html(""+getTodayDate());
//  $('#myaccrdion').accordion({animate:false,border:false,height:700,selected:0});
  tabClose();
  createTab();
  getProjectProgress();
  getProjectProgress();
  getReadyToApprovalBill();
//  getReadyToCreateBill();
  $('#tt').tabs({   
		border:false,   
		onSelect:function(title){   
//			if(title=="待制单") {
//				getReadyToCreateBill();
//			}
			if(title=="待批复") {
				getProjectProgress();
				getReadyToApprovalBill();
			}
			if(title=="已批复") {
				getProjectProgress();
				getAlreadyToApprovalBill();
			}
		}   
	}); 
});
function addTab(menuid,title,url,icon){
   if(!$("#tabs").tabs('exists',title)){
   	 $("#tabs").tabs('add',{
   	   id:menuid,
       title:title,
       content:createFrame(url),
       closable:true,
       iconCls:icon
     });
   }else{
      $('#tabs').tabs('select',title);
      $('#mm-tabupdate').click();
   }   
   tabClose();
}

function tabClose(){
  /*双击关闭TAB选项卡*/
  $(".tabs-inner").dblclick(function(){
	var subtitle = $(this).children(".tabs-closable").text();
	$('#tabs').tabs('close',subtitle);
  })
}
function createTab(){
   $('.navlist li a').click(function(){
      var tabTitle = $(this).children('.nav').text();
      var url = $(this).attr("rel");	
      var menuids = $(this).attr("ref");     
	  var iconCls = $(this).find('.icon').attr('class');
	  addTab(menuids,tabTitle,url,iconCls);
	  $('.navlist li div').removeClass("selected");
	  $(this).parent().addClass("selected");
   }).hover(function(){
   	  $(this).parent().addClass("hover");
   },function(){
   	  $(this).parent().removeClass("hover");
   });   
}
function getWelcomeByTime(){
  var now = new Date();
  var hours = now.getHours();
  var timeValue = (hours >= 12) ? "下午好" : "上午好";
  return timeValue;
}
function logout(){	
	$.messager.confirm('系统提示','确定要退出本平台吗？',function(r){
	   if(r){
		   var browser = navigator.userAgent;
		   if(browser.indexOf("Chrome") != -1 || browser.indexOf("Firefox") != -1){
			   //谷歌、火狐
			   window.parent.location="userLoginController.do?method=logout";
		   }else{
			   //IE、360
			   window.parent.location="../userLoginController.do?method=logout";
		   }
	   }
	});
}
function updatePwd(){
   $('#pwdWin').window('open');
}
$("#btnCancel").click(function(){
   $('#pwdWin').window('close');
});
$("#btnEp").click(function(){
   var b = validPwd();   
   if(b){
      submitForm({
        formId:'saveForm',
        url:'userLoginController.do?method=updatePwd',
        callback:function(data){
           if(data=="SUCCESS"){ 
        	    $('#pwdWin').window('close');
   	  			$.messager.alert("系统提示","密码修改成功，请重新登录！","info",function(){   	  			   
   	  			   //退出
   	  			   var browser = navigator.userAgent;
   	  			   if(browser.indexOf("Chrome") != -1 || browser.indexOf("Firefox") != -1){
   	  				   //谷歌、火狐
   	  				   window.parent.location="userLoginController.do?method=logout";
   	  			   }else{
   	  				   //IE、360
   	  				   window.parent.location="../userLoginController.do?method=logout";
   	  			   }
   	  			});
   		   }else if(data=="EXIST"){   	  
   	  			$.messager.alert("系统提示","新密码与原密码相同，请重新输入！","warning");
           }else if(data=="FAIL"){   	  
   	  			$.messager.alert("系统提示","密码修改失败，请重试！","error");
           }else{
   	  			$.messager.alert("系统提示","修改密码时系统异常："+data,"error");	
           }
        }
      });
   } 
});
function validPwd(){
   var pwd1 = $("#txtNewPass").val();
   var pwd2 = $("#txtRePass").val();
   if(pwd1!=pwd2){
      $.messager.alert("系统提示","你两次输入的密码不一致，请重新输入！");
      return false;
   }
   return true;
}

//刷新当前Tab
function reload(){
	var tabIndex = -1;
	$(".tabs-title",parent.document).each(function(i){
		tabIndex = i;
	});
	for(tabIndex; tabIndex > 0; ){
		var tabIframe = parent.parent.document.getElementsByTagName("iframe")[tabIndex-3];
		if(!$(tabIframe).is(':hidden'))
			tabIframe.src = tabIframe.src;
		tabIndex --; 
	}
}


function getListCellValue(row, fieldName)
{
	var value = $(row).children("td[field$='"+fieldName+"']").children().eq(0).text();
	
	return value;
}